<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kafka 数据可靠性保障机制</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border: 1px solid rgba(102, 126, 234, 0.3);
        }
        
        .number-circle {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            color: white;
            font-weight: bold;
            flex-shrink: 0;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-tag {
            background: #f3f4f6;
            padding: 2px 8px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 14px;
            color: #4b5563;
            border: 1px solid #e5e7eb;
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fade-in">
                <h1 class="text-5xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                    Kafka 数据可靠性保障机制
                </h1>
                <p class="text-xl opacity-90 leading-relaxed">
                    深入解析 Apache Kafka 如何通过多层次的技术架构，确保在分布式环境下的数据零丢失
                </p>
                <div class="mt-8 flex justify-center space-x-8">
                    <div class="text-center">
                        <i class="fas fa-shield-alt text-3xl mb-2"></i>
                        <p class="text-sm">高可靠性</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-sync-alt text-3xl mb-2"></i>
                        <p class="text-sm">自动恢复</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-database text-3xl mb-2"></i>
                        <p class="text-sm">数据持久化</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-6xl mx-auto">
            
            <!-- Introduction Card -->
            <div class="bg-white rounded-xl shadow-lg p-8 mb-12 card-hover animate-fade-in">
                <div class="flex items-start">
                    <i class="fas fa-info-circle text-3xl feature-icon mr-4 mt-1"></i>
                    <div>
                        <h2 class="text-2xl font-bold mb-4 text-gray-800">核心概述</h2>
                        <p class="text-gray-600 leading-relaxed text-lg">
                            Kafka 通过副本机制、ISR 机制、配置项和日志清理等多种方法来解决数据丢失问题。这些机制和策略共同工作，确保 Kafka 系统能够在面对节点故障、网络问题和其他挑战时，保持数据的高可用性和一致性。
                        </p>
                    </div>
                </div>
            </div>

            <!-- Architecture Diagram -->
            <div class="bg-white rounded-xl shadow-lg p-8 mb-12 card-hover">
                <h2 class="text-2xl font-bold mb-6 text-gray-800 text-center">Kafka 数据保障架构图</h2>
                <div class="mermaid">
                    graph TB
                        A[生产者] -->|写入数据| B[Leader副本]
                        B -->|数据复制| C[Follower副本1]
                        B -->|数据复制| D[Follower副本2]
                        B -->|数据复制| E[Follower副本3]
                        
                        C -.->|ISR同步| F[ISR列表]
                        D -.->|ISR同步| F
                        E -.->|ISR同步| F
                        
                        F -->|确认机制| G[写入确认]
                        G -->|acks=all| A
                        
                        B -->|持久化| H[日志文件]
                        H -->|顺序写入| I[磁盘存储]
                        
                        J[消费者] -->|读取数据| B
                        J -->|保存偏移量| K[偏移量存储]
                        
                        style A fill:#667eea,stroke:#fff,color:#fff
                        style B fill:#764ba2,stroke:#fff,color:#fff
                        style F fill:#f59e0b,stroke:#fff,color:#fff
                        style H fill:#10b981,stroke:#fff,color:#fff
                </div>
            </div>

            <!-- Feature Sections -->
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-12">
                
                <!-- 1. 副本机制 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover animate-fade-in">
                    <div class="flex items-center mb-6">
                        <div class="number-circle">1</div>
                        <h3 class="text-xl font-bold ml-4 text-gray-800 section-title">副本机制</h3>
                    </div>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <i class="fas fa-copy text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700 mb-2">副本架构</h4>
                                <p class="text-gray-600">每个 Kafka 分区都有一个主副本（Leader）和多个从副本（Follower）。Leader 处理所有的读写请求，而从副本从 Leader 拉取数据以保持同步。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-sync text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700 mb-2">数据复制</h4>
                                <p class="text-gray-600">所有写入到 Leader 的数据都会被复制到 ISR 列表中的从副本。这确保了即使 Leader 副本发生故障，ISR 中的副本仍然持有数据副本。</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 2. ISR机制 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover animate-fade-in">
                    <div class="flex items-center mb-6">
                        <div class="number-circle">2</div>
                        <h3 class="text-xl font-bold ml-4 text-gray-800 section-title">ISR 机制</h3>
                    </div>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <i class="fas fa-check-double text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700 mb-2">同步副本</h4>
                                <p class="text-gray-600">ISR 列表中的副本是与 Leader 副本同步的数据副本。Kafka 只允许 ISR 中的副本进行数据读取，确保数据的一致性。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-handshake text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700 mb-2">写入确认</h4>
                                <p class="text-gray-600">写入请求只有在 ISR 中的副本确认之后才会被认为成功。这保证了写入操作在多个副本中都得到了确认。</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 3. 日志持久化 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover animate-fade-in">
                    <div class="flex items-center mb-6">
                        <div class="number-circle">3</div>
                        <h3 class="text-xl font-bold ml-4 text-gray-800 section-title">日志持久化</h3>
                    </div>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <i class="fas fa-stream text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700 mb-2">顺序写入</h4>
                                <p class="text-gray-600">Kafka 使用顺序写入的方式将数据追加到日志文件中，最大限度地减少了磁盘 I/O 的开销。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-hdd text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700 mb-2">数据持久化</h4>
                                <p class="text-gray-600">通过配置 <span class="code-tag">log.retention.hours</span>、<span class="code-tag">log.retention.bytes</span> 等参数控制日志的持久化策略。</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 4. 消息确认机制 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover animate-fade-in">
                    <div class="flex items-center mb-6">
                        <div class="number-circle">4</div>
                        <h3 class="text-xl font-bold ml-4 text-gray-800 section-title">消息确认机制</h3>
                    </div>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <div>
                                <h4 class="font-semibold text-gray-700 mb-2">生产者确认</h4>
                                <p class="text-gray-600 mb-3">Kafka 生产者可配置 <span class="code-tag">acks</span> 参数：</p>
                                <ul class="space-y-2 ml-4">
                                    <li class="flex items-center"><i class="fas fa-angle-right text-purple-400 mr-2"></i><span class="code-tag">acks=0</span>：不等待确认</li>
                                    <li class="flex items-center"><i class="fas fa-angle-right text-purple-400 mr-2"></i><span class="code-tag">acks=1</span>：等待 Leader 确认</li>
                                    <li class="flex items-center"><i class="fas fa-angle-right text-purple-400 mr-2"></i><span class="code-tag">acks=all</span>：等待 ISR 所有副本确认</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Additional Features -->